﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Skyhook.Isometry
{
    static internal class BoundsChecker
    {
        static private void ValidateBound(float min, float max)
        {
            if (max <= min)
            {
                throw new Exception("Max lesser or equal to min (" + min.ToString() + "," + max.ToString() + ")");
            }
        }
        static public bool IsCoordinateInBound(float coord, float min, float max)
        {
            ValidateBound(min, max);

            if (coord < min)
            {
                return false;
            }

            if (coord >= max)
            {
                return false;
            }

            return true;
        }

        static public bool IsPointInRect(Point point, Rectangle rectangle)
        {
            return BoundsChecker.IsCoordinateInBound(point.X, rectangle.X, rectangle.Width) && 
                BoundsChecker.IsCoordinateInBound(point.Y, rectangle.Y, rectangle.Height);
        }

        static public float GetCorrectCoordinate(float coord, float min, float max)
        {
            ValidateBound(min, max);

            float result = coord;
            if (result < min)
            {
                result = min + 0.5f;
            }

            if (result >= max)
            {
                result = max - 0.5f;
            }

            return result;
        }
    }
}
